package cn.rengy.web.framework.wxmp.user;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.rengy.lang.ResultEntity;
import cn.rengy.lang.WeChatException;
import cn.rengy.web.framework.wxmp.message.WXAppMessageService;


/**
 * 
 * 
 */
@Controller
@RequestMapping(value = "/authenticated/wxuser")
public class WxUserController {
	private static Logger logger = LoggerFactory.getLogger(WxUserController.class);
	@Autowired
	private WxUserService wxUserService;
	@Autowired
	private WXAppMessageService wXAppMessageService;
	
	/**
	 * 同步用户
	 * @param paramMap
	 * @return
	 * @throws WeChatException 
	 */
	@RequestMapping(value="synchronize",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity synchronizeUser (@RequestBody Map<String,Object> paramMap) throws WeChatException{
		String appid=MapUtils.getString(paramMap, "appid");
		wxUserService.synchronizeAllUser(appid);
		return ResultEntity.ok();
	}
	
	@RequestMapping(value="updateUserInfo",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity updateUserInfo (@RequestBody Map<String,Object> paramMap) throws WeChatException{
		wxUserService.synchronizeUserInfo(paramMap);
		return ResultEntity.ok();
	}
	
	/**
	 * 发送客服消息
	 * @param paramMap
	 * @return
	 */
	@RequestMapping(value="/customerMsg",method = RequestMethod.POST)
	@ResponseBody
	public ResultEntity customerMsg (@RequestBody Map<String,Object> paramMap){
		wXAppMessageService.customerMsg(paramMap);
		return ResultEntity.ok();
	}
}
